package com.gxuwz.easyschool.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.gxuwz.easyschool.R;
import com.gxuwz.easyschool.holder.NewsBulletinHolder;

public class NewsBulletinAdapter extends BaseAdapter {
    private String[] titles = {"2022级新生绑卡情况","北校区断电情况","水费、电费充值注意事项","充值过程显示错误代码：90015..."};
    private String[] times = {"2022-08-30 14:58:20","2022-08-27 14:58:20","2022-08-23 14:58:20","2022-08-11 14:58:20"};
    private String[] resource = {"来源：一卡通技术","来源：一卡通技术","来源：一卡通技术","来源：一卡通技术"};
    private Context context;
    public NewsBulletinAdapter(Context context){
        this.context = context;
    }

    @Override
    public int getCount() {
        return titles.length;
    }

    @Override
    public Object getItem(int position) {
        return titles[position];
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        NewsBulletinHolder newsBulletinHolder = null;
        if(convertView == null){
            convertView = LayoutInflater.from(context).inflate(R.layout.news_bulletin_list,null);
            newsBulletinHolder = new NewsBulletinHolder();
            newsBulletinHolder.setNews_title(convertView.findViewById(R.id.news_title));
            newsBulletinHolder.setNews_time(convertView.findViewById(R.id.news_time));
            newsBulletinHolder.setNews_resource(convertView.findViewById(R.id.news_resource));
            if (position == 0){
                newsBulletinHolder.setNews_pic(convertView.findViewById(R.id.news_pic));
            }
            convertView.setTag(newsBulletinHolder);
        } else {
            newsBulletinHolder = (NewsBulletinHolder) convertView.getTag();
        }
        newsBulletinHolder.getNews_title().setText(titles[position]);
        newsBulletinHolder.getNews_time().setText(times[position]);
        newsBulletinHolder.getNews_resource().setText(resource[position]);
        if (position == 0){
            newsBulletinHolder.getNews_pic().setBackgroundResource(R.drawable.new_icon);
        }
        return convertView;
    }
}
